package com.bainuo.doctor.common.image_support.imghandle.picker;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by bainuo on 2017/2/10.
 */

public class SingleImagePicker extends BasePicker {


    @Override
    public void pickFromAlbum() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);   //Pick an item fromthe data
        intent.setType("image/*");              //从所有图片中进行选择
        activity.startActivityForResult(intent, code);
    }

    @Override
    public void pickFromCamera() {

    }

//    @Override
//    public Uri getUri(Intent data) {
//        if (data != null)
//            return data.getData();
//        return null;
//    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == code) {
            if (resultCode == Activity.RESULT_OK) {
                if (listener != null && data != null) {

                    List<Uri> list = new ArrayList<>();
                    list.add(data.getData());
                    listener.onPictureSelected(list, null);
                }
            } else {

            }
        }
    }
}
